Displaying Alternate Text for an Image

Sometimes, an inserted image does not appear in a Web browser because of the incorrect file path or invalid file name specified in the src attribute of the <img> tag. In that case, you can specify an alternate text for an image.

The alternate text for an image is sisplayed when the image is not visible on the web page. In other words, alternate text is used in case the image is not rendered by the browser.

The basic purpose of adding an alternate text is to provide a short description about an image so that users can get an idea of what the image is all about, in case the image is not displayed on a Web browser. To apply an alternate text to an image, you can use the alt attribute of the <img> tag. If the image is visible, you can see the alternate text by placing the mouse pointer over the image.

Let’s do the following steps to display an alternate text for an image:


<!DOCTYPE html>
<html>
<head>
    <title> Image </title>
</head>
<body>
    <h1>Displaying Alternate Text for an Image</h1>
    <img src=”images\globe.jpg” alt=”Globe Cartoon” />
    <img src=”” alt=”Global Teacher” />
</body>
</html>

Save the document with the name AlternateText.html and open on browser: